﻿using BCC.ViewModel.login;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace BCC.login
{
    /// <summary>
    /// loginWindow.xaml 的交互逻辑
    /// </summary>
    public partial class loginWindow : Window
    {
        public loginWindow()
        {
            InitializeComponent();
        }

        private void LoginBtn_Click(object sender, RoutedEventArgs e)
        {
            var bccUser= loginVM.selLogin(txtEmail.Text, txtPassword.Password);
            if (bccUser!=null)
            {
                BCC.Communication.SocketClient.client client = new BCC.Communication.SocketClient.client();
                
                MainWindow mainWindow = new MainWindow(bccUser, client);
                mainWindow.Show();
                string serverAddress = ConfigurationManager.AppSettings["serverSocketAddress"].Trim();
                client.connected(serverAddress, 5566);
                client.sendLoginMes(txtEmail.Text);

                this.Close();
            }
        }
    }
}
